﻿@using ChampionsLeagueBets.Domain
@using MvcContrib.Pagination
@using MvcContrib.UI.Pager
@using MvcContrib.UI.Grid;
@model IList<User>
@{
	ViewBag.Title = "Lista graczy";
	ViewBag.Image = "~/Content/images/user-64.png";
}

<div id="content-list">
	<div id="PartialToRefresh">
		@Html.Partial("_UsersList", Model)
	</div>
</div>

<div class="ui-actions">
	@(Html.ActionLink<UsersController>(c => c.Create(), "Dodaj", new { @class = "link-button" }))
	@(Html.ActionLink<HomeController>(c => c.Administration(), "Anuluj", new { @class = "link-button" }))
</div>
<div id="dialog-confirm" title="Usunąć gracza?">
	<p>
		<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
		Dane gracza zostaną usuniętę. Kontynuować?</p>
</div>

<script language="javascript" type="text/javascript">

	$(document).ready(function () {

		$("#dialog-confirm").dialog({
			autoOpen: false,
			modal: true,
			resizable: false,
			height: 180
		});

		RefreshJavaScript();
	});

	function RefreshJavaScript() {

		$(".deleteLink").click(function (e) {
			e.preventDefault();
			var targetUrl = $(this).attr("href");

			$("#dialog-confirm").dialog({
				buttons: {
					"Usuń": function () {
						//window.location.href = targetUrl;
						$.ajax({
							url: targetUrl,
							success: function (html) {
								$("#PartialToRefresh").html(html);
								SucessDelete();
								RefreshJavaScript();
							}
						});
						$(this).dialog("close");
					},
					"Anuluj": function () {
						$(this).dialog("close");
					}
				}
			});

			$("#dialog-confirm").dialog("open");
		});
	}

	function SucessDelete() {
		$("#page-message-contener").html("<div id='page-message'><div id='page-message-success'>Gracz został usunięty.</div></div>");
		window.ShowPageMessage();
	}
	
</script>